package com.dhp.campus.contoller;

import com.dhp.campus.Common.ErrorCode;
import com.dhp.campus.Common.Result;
import com.dhp.campus.Common.ResultUtils;
import com.dhp.campus.Exception.exception;
import com.dhp.campus.domain.request.GetPrivateChartRequest;
import com.dhp.campus.domain.vo.MessageVo;
import com.dhp.campus.service.ChatService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@RequestMapping("/chat")
public class ChartController {

    @Autowired
    private ChatService chatService;


    @PostMapping("/privateChat")
    public Result<List<MessageVo>> getPrivateChartMessage(@RequestBody GetPrivateChartRequest privateChartRequest , HttpServletRequest request){
        if (privateChartRequest == null){
            throw new exception(ErrorCode.PARAMS_EMPTY);
        }
        List<MessageVo> messageVoList = chatService.getPrivateChartMessage(privateChartRequest , request);
        return ResultUtils.success(messageVoList);
    }
}
